
/**
 * 解析路径：如/174/fuel/remit/.stationId_234-stationName_testee33-userId_745-utmSource_1
 * 返回 一个对象
 * 包含 enterpriseId ： 174
 * firstUrl： 路径（除了查询字符串部分 /174/fuel/remit/）
 * fullUrl: "/174/fuel/remit/?stationId=234&stationName=testee33&userId=745&utmSource=1"
 * searchObj{
 *  stationId: "234"  油站id
 *  stationName: "testee33" ： 油站名称
 *  userId: "745" ： 加油员的用户id
 *  utmSource: "1" : 订单来源， 只要扫码进来，值都是1
 * }
 * 
 * **/ 
import querystring from "querystring";
export function parseExtStr(extStr) {
    let searchObj;
    let searchStr;
    let enterpriseId;

    const [url, str] = extStr.split(".");
    if (str !== undefined) {
      searchStr = str.replace(/-/g, "&").replace(/_/g, "=");
      searchObj = querystring.parse(searchStr);
    } else {
      searchStr = "";
      searchObj = {};
    }

    let enterpriseIdArr = url.replace(/\//, "").match(/^\d{1,}/);
    if (enterpriseIdArr == null) {
      enterpriseId = "";
    } else {
      enterpriseId = enterpriseIdArr[0];
    }

    return {
      fullUrl: url + (searchStr != "" ? "?" : "") + searchStr,
      firstUrl: url,
      searchObj,
      enterpriseId
    };
  }